package ar.edu.uba.fi.jmit.graphvisualizer.server.storage;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

public class DataStorage extends MonitorDataStorage {

	private Map<String, ApplicationStorage<Map<String, Serializable>>> applications;
	
	public DataStorage() {
		super();
		applications = new HashMap<String, ApplicationStorage<Map<String,Serializable>>>();
	}
	
	@Override
	protected void addData(String applicationName, String monitorName, Date date,
			Map<String, Serializable> dataMap) {
		
		ApplicationStorage<Map<String, Serializable>> monitorStorage = applications.get(applicationName);
		if(monitorStorage == null) {
			monitorStorage = new ApplicationStorage<Map<String, Serializable>>();
			applications.put(applicationName, monitorStorage);
		}
		monitorStorage.add(monitorName, date, dataMap);
		
	}

	@Override
	public List<Pair<Map<String, Serializable>>> getData(String application,
			String monitorName) {
		if(!applications.containsKey(application)) {
			Logger.getLogger(this.getClass()).debug("No data info for application name: " + application);
			return new LinkedList<Pair<Map<String,Serializable>>>();
		}
		return applications.get(application).get(monitorName);
	}

}
